/*
 *  $Id: SinlessDemon.cs 1051 2010-05-18 22:10:41Z thenn.erannor $
 *	This file is a part of Ragima CCG.
 *	(C) 2008 Ragima development group.
 *
 *	Licensed under the terms of the GNU GPL License version 2.
 *
 */

using System;

namespace Ragima.Cards001.Light.Creatures {
    public class SinlessDemon: DemonCreatureCard {
        public SinlessDemon(): base("001_l_c_sinless_demon") {
            Level = CompleteLevel.ReadyForTest;
            Element = ElementType.Light;
            Value = 100;
            Damage = 5;
            Health = 2;
			AddManaCost(ElementType.Light, 4);
			AddManaCost(ElementType.Darkness, 2);
            PactValue = 5;
        }

        public override void SetNaturalAffects(ICollector<Affect> affects) {
            base.SetNaturalAffects(affects);
            affects.Add(new Affects.ModTakenDamage(DamageType.PhysicalAttack, -3));
            affects.Add(new Affects.ModTakenDamage(DamageType.MagicAttack, -3));
            affects.Add<Affects.FlightBlock>();
            affects.Add<Affects.Antimagic>();
        }

        public override void ExecutePact(Player owner) {
            Player enemy = owner.Enemy;
            int max = Math.Max(GetSumHealth(owner), GetSumHealth(enemy));
            DistributeHealth(owner, max);
            DistributeHealth(enemy, max);
        }

        private static int GetSumHealth(Player player) {
            int sum = 0;
            foreach (Creature cr in player.GetCreatures()) sum += cr.Health;
            return sum;
        }

        private static void DistributeHealth(Player player, int sum) {
            int count = player.GetCreatureCount();
            int newHealth = (sum+count-1)/count;
            foreach (Creature cr in player.GetCreatures()) cr.SetHealth(newHealth);
        }
    }
}
